import React, { Component } from 'react';

import DetailModel from '../../models/detailModel'
import Loading from '../../components/Loading'

import { Button } from 'antd-mobile'

class index extends Component {
  constructor(props) {
    super(props)
    this.state = {
      id: this.props.match.params.id || 0,
      info: {}
    }
  }

  async componentDidMount() {
    // 类的静态方法调用
    let ret = await DetailModel.getDetail()
    this.setState(state => {
      return {
        info: ret.data.data
      }
    })
  }

  addFav = id => {
    // ajax
    console.log(id);
  }

  render() {
    let { info } = this.state
    return (
      <div>
        {!info.name ? <Loading /> : (
          <>
            <h3>{info.name}</h3>
            <Button type="primary" onClick={this.addFav.bind(this, info.code)}>收藏一下</Button>
          </>
        )}

      </div>
    );
  }
}

export default index;
